/**
 * Filename: AlbumMemberAdapter.java
 *
 * @author Firefly
 * @contact postfirefly@163.com
 * @time 2016/3/8 12:11
 */
package com.github.postsanf.yinian.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.bean.YNHongBaoChart;
import com.github.postsanf.yinian.utils.ImageOptHelper;
import com.github.postsanf.yinian.utils.StringUtils;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.imageaware.ImageViewAware;

import java.util.List;


public class HongbaoChartAdapter extends RecyclerView.Adapter<HongbaoChartAdapter.ViewHolder> {
    private Context mContext;
    private List<YNHongBaoChart> datas;
    private ImageLoader imageLoader;

    public HongbaoChartAdapter(Context mContext, List<YNHongBaoChart> datas) {
        this.mContext = mContext;
        this.datas = datas;
        imageLoader = ImageLoader.getInstance();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout ll_item_album_member;                                //列表View
        ImageView iv_item_album_member_avatar;                        //成员头像
        TextView tv_item_album_member_username;                        //成员名
        TextView rl_item_album_num;

        public ViewHolder(View itemView) {
            super(itemView);
            ll_item_album_member = (LinearLayout) itemView
                    .findViewById(R.id.ll_item_album_member);
            iv_item_album_member_avatar = (ImageView) itemView
                    .findViewById(R.id.iv_item_album_member_avatar);
            tv_item_album_member_username = (TextView) itemView
                    .findViewById(R.id.tv_item_album_member_username);
            rl_item_album_num = (TextView) itemView
                    .findViewById(R.id.rl_item_album_num);
        }

        public void bindData(final YNHongBaoChart listItems, final int point) {
            if (listItems != null) {
                imageLoader.displayImage(listItems.getUpic() + StringUtils.getQulity(),
                        new ImageViewAware(iv_item_album_member_avatar, false),
                        ImageOptHelper.getAvatarOptions());
                tv_item_album_member_username.setText(listItems.getUnickname());
                rl_item_album_num.setText(String.valueOf(listItems.getGrabMoney())+"元");
            }
        }
    }

    private YNHongBaoChart getItem(int position) {
        return datas.get(position);
    }


    // 创建ViewHolder
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.yn_item_hongbao_chart, parent, false));
    }


    @Override
    public int getItemViewType(int position) {
        return super.getItemViewType(position);
    }

    // 绑定数据到View
    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        YNHongBaoChart listItems = getItem(position);
        holder.bindData(listItems, position);
        holder.itemView.setTag(listItems);
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }
}
